﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace QuangMobile
{
    public partial class UCContent : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //LoadTab();
            LoadProductBlockList();
        }

        protected void LoadProductBlockList()
        {
            string sql = "SELECT * FROM dbo.tblWebDanhMuc WHERE MaDM = 'Nhom' AND IsShow = 1";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string sSql = "SELECT TOP 4 * FROM dbo.tblWebSanPham WHERE NhomID_DM = @ID ORDER BY UpdateDate DESC";
                List<SqlParameter> arrParams = new List<SqlParameter>();
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dt.Rows[i]["ID"]));
                DataTable Pdt = SqlHelper.ExecuteDataTable(CommandType.Text, sSql, arrParams);
                UCProductBlock Block = (UCProductBlock)LoadControl("UCProductBlock.ascx");
                Block.Title = "<a href='NhomSanPham.aspx?mod=" + dt.Rows[i]["ID"].ToString() + "'>" + dt.Rows[i]["TenDM"].ToString() + "</a>";
                Block.ListProduct = Pdt;
                ProductBlockList.Controls.Add(Block);
            }
        }

        protected void LoadTab()
        {
            string sql = "SELECT * FROM dbo.tblWebDanhMuc WHERE MaDM = 'nhom'";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string sSql = "SELECT TOP 8 * FROM dbo.tblWebSanPham WHERE NhomID_DM = @ID ORDER BY UpdateDate DESC";
                List<SqlParameter> arrParams = new List<SqlParameter>();
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, dt.Rows[i]["ID"]));
                DataTable ListProduct = SqlHelper.ExecuteDataTable(CommandType.Text, sSql, arrParams);
                AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel();
                for (int j = 0; j < ListProduct.Rows.Count; j++)
                {
                    UCProductItem Item = (UCProductItem)LoadControl("UCProductItem.ascx");
                    Item.ProductID = Convert.ToInt32(ListProduct.Rows[j]["ID"]);
                    if (ListProduct.Rows[i]["AnhSP"] == DBNull.Value)
                    {
                        Item.ProductImage = "../upload/no-image.png";
                    }
                    else
                    {
                        Item.ProductImage = ListProduct.Rows[i]["AnhSP"].ToString();
                    }
                    Item.ProductTitle = ListProduct.Rows[j]["TenSP"].ToString();
                    Item.ProductPrice = Convert.ToDouble(ListProduct.Rows[j]["GiaSP"]);
                    Item.ProductComment = ListProduct.Rows[j]["MoTa"].ToString();
                    tab.Controls.Add(Item);
                    Item = null;
                }
                tab.HeaderText = dt.Rows[i]["TenDM"].ToString();
            }
        }


    }
}